package handler

import (
	"github.com/name5566/leaf/gate"
	"server/game/bag"
	"server/game/level"
	"server/msg/jsonData"
)

func GetPlayerLevelInfo(args []interface{}) {
	m := args[0].(*jsonData.MsgLevelInfo)
	a := args[1].(gate.Agent)
	levelInfo, err := level.GetPlayerLevelInfo(m.UserId)
	if err != nil {
		a.WriteMsg(&jsonData.MsgRes{Ret: 1, Message: err.Error(), RequestId: m.RequestId})
		return
	}
	a.WriteMsg(&jsonData.MsgRes{Ret: 0, Result: levelInfo, RequestId: m.RequestId})
}
func IncreaseLevelProgress(args []interface{}) {
	m := args[0].(*jsonData.MsgIncreaseLevelProgress)
	a := args[1].(gate.Agent)
	err := level.IncreaseLevelProgress(m.UserId, m.Level)
	if err != nil {
		a.WriteMsg(&jsonData.MsgRes{Ret: jsonData.ErrCode(10), Message: err.Error(), RequestId: m.RequestId})
		return
	}
	backLogic := bag.NewBackpack(m.UserId, bag.Bagsiz)
	itemList := backLogic.ListItems()
	a.WriteMsg(&jsonData.MsgRes{Ret: jsonData.ErrCode(0), Result: itemList, RequestId: m.RequestId})
}
func BossBattle(args []interface{}) {
	m := args[0].(*jsonData.MsgBossBattle)
	a := args[1].(gate.Agent)
	check, err := level.BossBattle(m.UserId, m.Level)
	if err != nil || !check {
		a.WriteMsg(&jsonData.MsgRes{Ret: 1, Message: "战斗失败", RequestId: m.RequestId})
		return
	}
	levelInfo, _ := level.GetPlayerLevelInfo(m.UserId)
	a.WriteMsg(&jsonData.MsgRes{Ret: jsonData.ErrCode(0), Result: levelInfo, RequestId: m.RequestId})
}
func LevelZhaoGong(args []interface{}) {
	m := args[0].(*jsonData.MsgLevelZhaoGongReq)
	a := args[1].(gate.Agent)
	ret, err := level.ZhaoGong(m.UserId, m.CardId)
	if err != nil {
		a.WriteMsg(&jsonData.MsgRes{Ret: 1, Message: "战斗失败", RequestId: m.RequestId})
		return
	}
	a.WriteMsg(&jsonData.MsgRes{Ret: jsonData.ErrCode(0), Result: ret, RequestId: m.RequestId})
}
func LevelPeiXun(args []interface{}) {
	m := args[0].(*jsonData.MsgPeiXunGongReq)
	a := args[1].(gate.Agent)
	ret, err := level.PeiXun(m.UserId, m.CardId)
	if err != nil {
		a.WriteMsg(&jsonData.MsgRes{Ret: 1, Message: "战斗失败", RequestId: m.RequestId})
		return
	}
	a.WriteMsg(&jsonData.MsgRes{Ret: jsonData.ErrCode(0), Result: ret, RequestId: m.RequestId})
}

//func BossBattle(args []interface{}) {
//	m := args[0].(*jsonData.MsgBossBattle)
//	a := args[1].(gate.Agent)
//	check, err := level.BossBattle(m.UserId, m.Level)
//	if err != nil || !check {
//		a.WriteMsg(&jsonData.MsgRes{Ret: 1, Message: "战斗失败", RequestId: m.RequestId})
//		return
//	}
//	levelInfo, _ := level.GetPlayerLevelInfo(m.UserId)
//	a.WriteMsg(&jsonData.MsgRes{Ret: jsonData.ErrCode(0), Result: levelInfo, RequestId: m.RequestId})
//}
//func BossBattle(args []interface{}) {
//	m := args[0].(*jsonData.MsgBossBattle)
//	a := args[1].(gate.Agent)
//	check, err := level.BossBattle(m.UserId, m.Level)
//	if err != nil || !check {
//		a.WriteMsg(&jsonData.MsgRes{Ret: 1, Message: "战斗失败", RequestId: m.RequestId})
//		return
//	}
//	levelInfo, _ := level.GetPlayerLevelInfo(m.UserId)
//	a.WriteMsg(&jsonData.MsgRes{Ret: jsonData.ErrCode(0), Result: levelInfo, RequestId: m.RequestId})
//}
